package insertSort;

import java.util.Arrays;
import java.util.Random;

/**
 * Created with IntelliJ IDEA.
 * Description:测试各种排序
 * User: 86187
 * Date: 2022-08-09
 * Time: 20:42
 */

public class TestInsertSort {
    //测试直接插入排序耗时
    public static void testInsertSort(int[] array) {
        long startTime = System.currentTimeMillis();
        MyInsertSort mySort = new MyInsertSort();
        mySort.insertSort(array);
        long endTime = System.currentTimeMillis();
        System.out.println("直接插入排序耗时:"+(endTime - startTime)+"ms");
    }

    public static void main(String[] args) {
        int[] array = new int[10_0000];
        //initArrayOrder(array);
        initArrayNotOrder(array);

        testInsertSort(array);
    }
    public static void initArrayOrder(int[] array) {
        //有序的初始化
        for (int i = 0; i < array.length; i++) {
            array[i] = i;
        }
    }
    public static void initArrayNotOrder(int[] array) {
        //不有序的初始化
        Random random = new Random();
        for (int i = 0; i < array.length; i++) {
            array[i] = random.nextInt(10_0000);
        }
    }//以上代码为了测试直接插入排序耗时的

    public static void main1(String[] args) {
        MyInsertSort mySort = new MyInsertSort();
        int[] array = {1,9,5,26,15,32,18,64,50};
        mySort.insertSort(array);
        System.out.println(Arrays.toString(array));
    }
}
